#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define MAX 100

using namespace std;

int stack[MAX];
int length;

void clear()
{
	memset(stack, 0, sizeof(int)*MAX);
	length = 0;
}

int getMax(int n)
{
	int max = 0;
	int index = -1;
	
	for(int i = 0; i <= n; i++)
	{
		if(max < stack[i])
		{
			max = stack[i];
			index = i;
		}
	}
	return index;
}

void flip(int bottom)
{
	int tmp;
	int middle = (bottom / 2);
	for(int i = 0; i <= middle; i++)
	{
		//stack[i]^=stack[bottom-i]^=stack[i]^=stack[bottom-i];
		tmp = stack[i];
		stack[i] = stack[bottom - i];
		stack[bottom - i] = tmp;
	}
}


void solve()
{
	int maxCake;
	for(int i=length-1; i > 0; i--)
	{
		maxCake = getMax(i);
		if(stack[i] != stack[maxCake])
		{
			if(stack[0] != stack[maxCake])
			{
				flip(maxCake);
				cout << length - maxCake << " ";
			}
			flip(i);
			cout << length - i << " ";
		}
	}
}

void read()
{
	char buf[1024];

	while(fgets(buf,1024,stdin) != NULL)
	{
		printf("%s\n", buf);
		clear();
		char *ptr = strtok(buf," ");
		while(ptr)
		{
			stack[length] = atoi(ptr);
			ptr = strtok(NULL," ");
			length++;
		}
		solve();
		cout << "0" << endl;
	}
}

int main()
{
	read();
	return 0;
}
